<!DOCTYPE html>
<html lang="en">

	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
		<meta name="description" content="">
		<meta name="author" content="">
		<!-- STYLESHEETS -->
		<!--[if lt IE 9]><script src="../../js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
		<link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
		<link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
		<link rel="stylesheet" type="text/css" href="../../css/responsive.css">
				<link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
		<!-- file-input -->
		<link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css" />
		<!-- SELECT2 -->
	<link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
		<!-- datatable -->
		<link rel="stylesheet" href="../../js/datatables/datatable.css">
		<!-- WIZARD -->
		<link rel="stylesheet" type="text/css" href="../../js/bootstrap-wizard/wizard.css" />

	</head>

	<body>
		<header class="navbar clearfix" id="header">
		</header>

		<!-- PAGE -->
		<section id="page">
			<!-- SIDEBAR -->
			<div id="sidebar" class="sidebar">
			<div class="sidebar-menu nav-collapse">
						
						<!-- SIDEBAR MENU -->
						<ul>							
							
							
						</ul>
						<!-- /SIDEBAR MENU -->
					</div>

			</div>
			<!-- /SIDEBAR -->
			<div id="main-content">
				<div class="container">
					<div class="row">
						<div id="content" class="col-lg-12">
							<!-- PAGE HEADER-->
							<div class="row">
								<div class="col-sm-12">
									<div class="page-header">
										<!-- STYLER -->

										<!-- /STYLER -->
										<!-- BREADCRUMBS -->
										<ul class="breadcrumb">
											<li>
												<i class="fa fa-home"></i>
												<a href="index.html">首页</a>
											</li>
											<li>
												<a href="#">订单管理</a>
											</li>
											<li>订单详情</li>
										</ul>
										<!-- /BREADCRUMBS -->

									</div>
								</div>
							</div>
							<!-- /PAGE HEADER -->
							<!-- SAMPLE -->

							<div class="row">
								<div class="col-md-12" style="background-color:#ffffff">
									<div class="box" style="margin-top:10px">
										<div class="box-title" style="border-bottom:1px solid #5e87b0;line-height:38px">
											<h4><i class="fa fa-file" style="color:red"></i>订单信息</h4>
											<a class="btn btn-default" href="track_order_list.html" style="float:right">返回订单列表</a>
										</div>
										<div class="box-body">
											<div class="form-group  mrg-bt10">
												<label class="control-label col-md-2 " style="width:100px"><span style="color:red">*</span>物流单号：</label>
												<div class="col-md-2 inline" >
												<input type="text" class="form-control" name="logisticsNo" placeholder="输入物流单号回车">
												</div>
												<label class="col-sm-1 control-label" for="e1" style="width: 108px"><span style="color:red">*</span>类型：</label>
													<div class="col-sm-2">
															<select id="status_select" name="workType" class="col-md-12 select2-offscreen" tabindex="-1">
															   <option value="-1">选择类型</option>
															   <option value="Lose">丢失</option>
															   <option value="Wrong">错发</option>
															   <option value="Leakage">漏发</option>
															    <option value="Other">其他</option>															    
															</select>												
													</div>
												
											</div>
											
										</div>
									</div>
									
									<div class="box">
										<div class="box-title" style="border-bottom:1px solid #5e87b0">
											<h4><i class="fa fa-archive" style="color:#468847"></i>商品信息</h4>
										</div>
										<div class="box-body">
											<div class="form-group" style="height:auto;">
												<table id="sku_list" class="table table-bordered">
													<thead>
													<tr>
													    <th></th>
													    <th>订单编号</th>	
														<th>商品名称</th>														
														<th>颜色/规格</th>														
														<th>单价</th>
														<th>数量</th>													
														</tr>
													</thead>
													<tbody>														
													</tbody>
												</table>
											</div>
										</div>
									</div>

									  <div class="form-group" >
									  <label class="col-sm-1 control-label"  style="width: 108px;line-height:50px"><span style="color:red">*</span>问题描述：</label>
										<div class="col-sm-4">
											<textarea rows="1" cols="100" class="form-control" id="description"></textarea>
										</div>
									  <label class="col-sm-1 control-label result"  style="width: 108px;line-height:50px;display:none">处理结果：</label>
									  <div class="col-sm-4 result" style="display:none">
									 	<textarea rows="1" cols="100" id="resultDesc" class="form-control" ></textarea>
									  </div>
									  </div>
								
									
									  <div class="form-group save" style="text-align: center;">
									     <a class="btn btn-primary">保存</a>
									 
									</div>
								</div>
							</div>

							<!-- /SAMPLE -->

							<div class="footer-tools">
								<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
							</div>
						</div>
						<!-- /CONTENT-->
					</div>
				</div>
			</div>
		</section>
		<!--/PAGE -->
		<!-- JAVASCRIPTS -->
		<!-- Placed at the end of the document so the pages load faster -->
		<!-- JQUERY -->
		<script src="../../js/jquery/jquery-2.0.3.min.js"></script>

		<!-- BOOTSTRAP -->
		<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>
		<!-- COOKIE -->
		<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
		<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
		<script type="text/javascript" src="../../js/select2/select2.min.js"></script>
		<!-- CUSTOM SCRIPT -->
		<script src="../../js/script.js"></script>
		<script src="../../js/common.js"></script>

		<script>
			var AddDetail = function() {
				var id,flag,resultDesc=null;
			
				var getStockDetail=function(){
					var no=$("[name=logisticsNo]").val();
					if(no==""){
						$.alert("请输入物流单号");
						return false;
					}
					$.ajax({
						type: "get",
						url: App.getContextPath() + "admin/trackorder/getStockOut.do",
						data: {
							logisticsNo: no
						},
						async: true,
						success: function(result) {
						   if(result!=null){
							   $("#sku_list tbody").empty();
							   $.each(result.detailsList,function(index,item){
								   
								   var tr="<tr><td><input type='checkbox' name='selecttr'  /></td><td>"+item.srcTid+"</td><td>"+item.goodsName+"</td><td>"+item.specName+"</td>"
								     +"<td>"+item.paid+"</td><td><input type=text class='form-control' name=amount value=1 style='width:100px'></td></tr>";
								    
								     $("#sku_list tbody").append(tr);  
							   });
							}
							
						 }
						});
				}
				
				var getDetail=function(){
					$.ajax({
						type: "get",
						url: App.getContextPath() + "admin/trackorder/getOrderTrackById.do",
						data: {
							id:id
						},
						async: true,
						success: function(result) {
						   if(result!=null){
							   $("#sku_list tbody").empty();
							   $.each(result.ygOrderTrackDetails,function(index,item){								   
								   var tr="<tr><td></td><td>"+item.srcId+"</td><td>"+item.productName+"</td><td>"+item.shortName+"</td>"
								     +"<td>"+item.price+"</td><td>"+item.amount+"</td></tr>";
								    
								     $("#sku_list tbody").append(tr);  
							   });
							}
						   $("[name=logisticsNo]").val(result.logisticsNo);
						   $("#status_select").select2("val",result.workType);
						   $("#description").text(result.description);
						   $("#resultDesc").text(result.resultDesc)
						 
							   $("[name=logisticsNo]").attr("disabled","disabled");
							   $("#status_select").attr("disabled","disabled").select2();
							   $("#description").attr("disabled","disabled");
							if(flag==2){								 
								   $("#resultDesc").attr("disabled","disabled"); 
								   $(".save").hide();
							   }
							$(".result").show();		   
							
						 }
						});
				}
				
				var save=function(){
					var track={};
					track.id=id;
					track.logisticsNo=$("[name=logisticsNo]").val();
					track.workType=$("#status_select").val();
					track.description=$("#description").val();
					track.resultDesc=$("#resultDesc").val();
					var details=[];
					$("#sku_list tbody tr").find("[name=selecttr]:checked").each(function(){
						var d={};
						var p=$(this).closest("tr");
						d.srcId=$(p).find("td:eq(1)").html();
						d.productName=$(p).find("td:eq(2)").html();
						d.shortName=$(p).find("td:eq(3)").html();
						d.price=$(p).find("td:eq(4)").html();
						d.amount=$(p).find("[name=amount]").val();
						details.push(d);
					});
					track.ygOrderTrackDetails=details;
					if(track.logisticsNo==""){
						$.alert("请输入物流单号")
						return false;
						
					}
					if(track.workType=="-1"){
						$.alert("请选择类型")
						return false;
						
					}
					if(track.description==""){
						$.alert("请输入问题描述")
						return false;						
					}
					if(details.length==0&&flag==0){
						$.alert("请选择商品信息")
						return false;		
					}
					$.ajax({
						type: "get",
						url: App.getContextPath() + "admin/trackorder/saveTrackOrder.do",
						data: {
							trackOrder: JSON.stringify(track)
						},
						async: true,
						success: function(result) {
						   if(result!=null){
							  location.href="track_order_list.html";
							}
						 }
						});
					
				}
				
				return {
					init: function() {
						App.init();
						 id=$.getUrlParam("id");
						 flag=$.getUrlParam("flag");
						 if(flag!=0)
							 getDetail();
						 
						 $("#status_select").select2({placeholder: "选择类型"});
						 $("[name=logisticsNo]").keypress(function(e){
							 if (e.which == 13) {
							 getStockDetail();
							 }
						 });
						 $(".save").click(save);
					
					}
				}
			}();
			$(function() {
				$("#header").load("../head.html");
				///$("#sidebar").load("../menu.html");
				AddDetail.init();
			});
		</script>

		<!-- /JAVASCRIPTS -->
	</body>

</html>